package cn.yunhe.service.impl;

import cn.yunhe.dao.RoleDao;
import cn.yunhe.entity.Permission;
import cn.yunhe.entity.Role;
import cn.yunhe.service.RoleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @program: ssm_insurance
 * @description: 角色
 * @author: 葛森
 * @create: 2018-09-15 16:44
 **/

@Service("roleService")
public class RoleServiceImpl  implements RoleService {

    @Resource
    private RoleDao roleDao;

    @Override
    public Page getAllRoleList(Map map) {

        Page page=new Page();
        int totleRows=roleDao.roleRountRows(map);
        int pageSize=Integer.parseInt(String.valueOf(map.get("pageSize")));
        int currPageNum=Integer.parseInt(String.valueOf(map.get("pageNum")));
        page.setTotal(totleRows);
        page.setPageSize(pageSize);
        page.setPageNum((Integer)(totleRows/pageSize+(totleRows%pageSize==0?0:1)));

        page= PageHelper.startPage(currPageNum,pageSize);
        List<Role> list= roleDao.getAllRoleList(map);
        return page;
    }

    @Override
    public boolean deleteRole(Role role) {
        return  roleDao.deleteRole(role);
    }

    @Override
    public Role getRoleById(Role role) {
        return roleDao.getRoleByid(role);
    }

    @Override
    public boolean updateRole(Role role) {
        return roleDao.updateRole(role);
    }

    @Override
    public boolean addRole(Role role) {
        return roleDao.addRole(role);
    }

    @Override
    public List<Role> searchAllRole() {
        return roleDao.searchAllRole();
    }

    @Override
    public List<Permission> getPermissionById() {
        return roleDao.getPermissionById();
    }

    @Override
    public boolean insertRolePermission(Map<String, Object> map) {
        return roleDao.insertRolePermission(map);
    }

    @Override
    public boolean delRolePermission(Map<String, Object> map) {
        return roleDao.delRolePermission(map);
    }

    @Override
    public List<Role> getAllRole() {
        return roleDao.getAllRole();
    }

    public RoleDao getRoleDao() {
        return roleDao;
    }

    public void setRoleDao(RoleDao roleDao) {
        this.roleDao = roleDao;
    }
}
